package com.xhcl.web.controller.system;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xhcl.common.annotation.Log;
import com.xhcl.common.core.controller.BaseController;
import com.xhcl.common.core.domain.AjaxResult;
import com.xhcl.common.core.page.TableDataInfo;
import com.xhcl.common.enums.BusinessType;
import com.xhcl.framework.shiro.util.ShiroUtils;
import com.xhcl.framework.uitls.poi.ExcelUtil;
import com.xhcl.system.domain.TSrhsYhsjjs;
import com.xhcl.system.service.ITGgDlyhwhService;
import com.xhcl.system.service.ITSrhsYhsjjsService;

/**
 * 银行数据接收Controller
 * 
 * @author xhcl
 * @date 2020-09-02
 */
@Controller
@RequestMapping("/system/yhsjjs")
public class TSrhsYhsjjsController extends BaseController
{
    private String prefix = "system/yhsjjs";

    @Autowired
    private ITSrhsYhsjjsService tSrhsYhsjjsService;
    
    @Autowired
    private ITGgDlyhwhService tGgDlyhwhService;

    @RequiresPermissions("system:yhsjjs:view")
    @GetMapping()
    public String yhsjjs(ModelMap mmap)
    {   
    	mmap.put("yhlist",tGgDlyhwhService.selectTGgDlyhwhList(null));
        return prefix + "/yhsjjs";
    }

    /**
     * 查询银行数据接收列表
     */
    @RequiresPermissions("system:yhsjjs:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TSrhsYhsjjs tSrhsYhsjjs)
    {
        startPage();
        List<TSrhsYhsjjs> list = tSrhsYhsjjsService.selectTSrhsYhsjjsForYhList(tSrhsYhsjjs);
        return getDataTable(list);
    }

    /**
     * 导出银行数据接收列表
     */
    @RequiresPermissions("system:yhsjjs:export")
    @Log(title = "银行数据接收", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TSrhsYhsjjs tSrhsYhsjjs)
    {
        List<TSrhsYhsjjs> list = tSrhsYhsjjsService.selectTSrhsYhsjjsForYhList(tSrhsYhsjjs);
        ExcelUtil<TSrhsYhsjjs> util = new ExcelUtil<TSrhsYhsjjs>(TSrhsYhsjjs.class);
        return util.exportExcel(list, "yhsjjs");
    }

    /**
     * 新增银行数据接收
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存银行数据接收
     */
    @RequiresPermissions("system:yhsjjs:add")
    @Log(title = "新增保存", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TSrhsYhsjjs tSrhsYhsjjs)
    {
        return toAjax(tSrhsYhsjjsService.insertTSrhsYhsjjs(tSrhsYhsjjs));
    }

    /**
     * 修改银行数据接收
     */
    @GetMapping("/edit/{lsh}")
    public String edit(@PathVariable("lsh") String lsh, ModelMap mmap)
    {
        TSrhsYhsjjs tSrhsYhsjjs = tSrhsYhsjjsService.selectTSrhsYhsjjsById(lsh);
        mmap.put("tSrhsYhsjjs", tSrhsYhsjjs);
        return prefix + "/edit";
    }

    /**
     * 修改保存银行数据接收
     */
    @RequiresPermissions("system:yhsjjs:edit")
    @Log(title = "修改保存", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TSrhsYhsjjs tSrhsYhsjjs)
    {
        return toAjax(tSrhsYhsjjsService.updateTSrhsYhsjjs(tSrhsYhsjjs));
    }

    /**
     * 删除银行数据接收
     */
    @RequiresPermissions("system:yhsjjs:remove")
    @Log(title = "删除银行数据", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(TSrhsYhsjjs tSrhsYhsjjs)
    {
        return toAjax(tSrhsYhsjjsService.deleteTSrhsYhsjjsById(tSrhsYhsjjs.getLsh()));
    }
   
    /**
     * 查询明细
     */
    @RequiresPermissions("system:yhsjjs:mxlist")
    @GetMapping("/detail/{lsh}")
    public String detail(@PathVariable("lsh") String lsh, ModelMap mmap)
    {
        mmap.put("lsh", lsh);
        return "system/incomemx/incomemx";
    }
    
    
    /**
     * 银行数据接收
     */
    @RequiresPermissions("system:yhsjjs:accept")
    @Log(title = "银行数据接收", businessType = BusinessType.UPDATE)
    @PostMapping( "/acceptData")
    @ResponseBody
    public AjaxResult acceptData(String lsh)
    {   
    	Map rsp=tSrhsYhsjjsService.acceptData(lsh,ShiroUtils.getLoginName());
    	if (rsp.get("outrev")!=null && rsp.get("outrev").equals("ok")) {
    		return AjaxResult.success();
    	}else {
    		return AjaxResult.error(rsp.get("outrev").toString());
    	}
       
    }
    
    /**
     * 银行数据接收
     */
    @RequiresPermissions("system:yhsjjs:unaccept")
    @Log(title = "撤销数据接收", businessType = BusinessType.UPDATE)
    @PostMapping( "/unacceptData")
    @ResponseBody
    public AjaxResult unacceptData(String pztxh)
    {   
    	Map rsp=tSrhsYhsjjsService.unacceptData(pztxh,ShiroUtils.getLoginName());
    	if (rsp.get("outrev")!=null && rsp.get("outrev").equals("ok")) {
    		return AjaxResult.success();
    	}else {
    		return AjaxResult.error(rsp.get("outrev").toString());
    	}
       
    }
}
